package com.tencentcloudapi.paiwukou;

import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/* ━━━━━━佛祖保佑━━━━━━
 *                  ,;,,;
 *                ,;;'(    社
 *      __      ,;;' ' \   会
 *   /'  '\'~~'~' \ /'\.)  主
 * ,;(      )    /  |.     义
 *,;' \    /-.,,(   ) \    码
 *     ) /       ) / )|    农
 *     ||        ||  \)
 *     (_\       (_\
 * ━━━━━━永无BUG━━━━━━
 * @author ：zjq
 * @date ：2020/12/25 15:18
 * @description: TODO
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 */
public class TestPaiWuKou {

    /**
     * 调用 排污口 登录 获取amdin 权限后 ，调用 问题列表 接口
     *
     * @param args
     */
    public static void main(String[] args) {

        RestTemplate restTemplate = new RestTemplate();

        // ######## 登录校验 ###################
        String loginUrl = "https://outfall.automaticox.com/outfall/api/auth/jwt/token";
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("username", "admin");
        jsonObj.put("password", "admin");
        JSONObject reLoginJson = restTemplate.postForObject(loginUrl, jsonObj, JSONObject.class);
        Map reLogin = (HashMap) reLoginJson.get("result");
        String loginToken = (String) reLogin.get("token");

//        ResponseEntity<JSONObject> aa = restTemplate.postForEntity(loginUrl, jsonObj, JSONObject.class);
//        System.out.println(aa.getBody());


        // ######## 疑似管理 列表  ###################
        String yisiListUrl = "https://outfall.automaticox.com/outfall/api/outfall/outfall/querySuspectedOutletInfoList";
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
        headers.set("Authorization", loginToken);

        JSONObject jsonT = new JSONObject();
        jsonObj.put("riverName", "长安东界河");
        jsonObj.put("pageNum", 1);
        jsonObj.put("pageNum", 10);

        HttpEntity requestEntity = new HttpEntity(jsonT, headers);
        JSONObject reYiSiList = restTemplate.postForObject(yisiListUrl, requestEntity, JSONObject.class);
        Map listMap = (HashMap) reYiSiList.get("result");
        List<Map<String, Object>> list = (List<Map<String, Object>>) listMap.get("list");

        list.stream().forEach(n -> {
            System.out.println(n.toString());
        });
    }


}
